import request from "@/api/request.js"
import {usetokenstore} from "@/store/token.js";

export const addBookService=(book)=>{
    const params = new URLSearchParams();
    for (let key in book){
        params.append(key,book[key])
    }

    return request.post("/book/addBook",params)
}


export const bookSearchService = (bookSearchDTO)=>{
    const params = new URLSearchParams()
    for(let key in bookSearchDTO){
        params.append(key,bookSearchDTO[key])
    }
    return request.post("/book/bookSearch",params)
}

export const deleteService=(id)=>{
    const params = new URLSearchParams()
    params.append("id",id)
    return request.post("/book/delete",params)
}

export const selectByIdService=(id)=>{
    const params = new URLSearchParams()
    params.append("id",id)
    return request.post("/book/selectById",params)
}

export const updateBookService=(updateBookDTO)=>{
    const params = new URLSearchParams()
    for(let key in updateBookDTO){
        params.append(key,updateBookDTO[key])
    }

    return request.post("/book/updateById",params)
}

export const deleteIdsService=(ids)=>{
    return request.post("/book/deleteIds",ids)
}

export const secondCategoryBookSearchService=(categorySearchDTO)=>{
    const params = new URLSearchParams()
    for (let key in categorySearchDTO){
        params.append(key,categorySearchDTO[key])
    }
    return request.post("/book/bookCategorySearch",params)
}

export const addBookSalesService=(addBookSaleDTOS)=>{
    const tokenstore=usetokenstore();

    return request.post("/book/addBookSales",addBookSaleDTOS,{headers:{'jwt':tokenstore.token}})
}

export const alertStatusService = (bookId)=>{
    const tokenstore=usetokenstore();
    const params = new URLSearchParams()
    params.append("bookId",bookId)
    console.log(bookId)
    return request.post("/book/alertStatus",params,{headers:{'jwt':tokenstore.token}})
}

export const getRecommendService = ()=>{
    const tokenstore=usetokenstore();

    return request.post("/book/getRecommendBooks",null,{headers:{'jwt':tokenstore.token}})

}

export const getBookSalesMostService = ()=>{
    const tokenstore=usetokenstore();

    return request.post("/book/getSalesMost",null,{headers:{'jwt':tokenstore.token}})

}

export const getRecentBookService = ()=>{
    const tokenstore=usetokenstore();

    return request.post("/book/getRecentBooks",null,{headers:{'jwt':tokenstore.token}})
}

export const getNewMostSaleBookService = ()=>{
    const tokenstore=usetokenstore();

    return request.post("/book/selectNewBookAndSalesMost",null,{headers:{'jwt':tokenstore.token}})
}
